﻿Public Class BenachrichtigungPopupForm

    Private _checkinout As Boolean

    Private WithEvents _closeTimer As System.Windows.Forms.Timer

    Private _autoCloseSeconds As Integer = 20

    Private WithEvents _showTimer As System.Windows.Forms.Timer

    Private _benachrichtigung As LibMultiPlug.Core.Benachrichtigungen.Benachrichtigung

    Public Sub New()

        ' Dieser Aufruf ist für den Designer erforderlich.
        InitializeComponent()

        ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.

        _closeTimer = New System.Windows.Forms.Timer

        _closeTimer.Interval = 1000

    End Sub


    Public Shadows Sub Show(ByVal b As LibMultiPlug.Core.Benachrichtigungen.Benachrichtigung)

        _benachrichtigung = b

        Me.Text = b.Info
        lblText.Text = b.Beschreibung
        lblModul.Text = b.Modul

        _closeTimer.Start()

        CoorpDesignLib.ControlFormater.GetInstance().RegisterControls(Me.Controls)

        MyBase.Show()

    End Sub

    Private Sub _closeTimer_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles _closeTimer.Tick

        _autoCloseSeconds -= 1

        If _autoCloseSeconds = 0 Then _
            Close()

        lblTime.Text = String.Format("in {0}s", _autoCloseSeconds)

    End Sub

    Protected Overrides Sub OnLoad(ByVal e As EventArgs)


        MyBase.OnLoad(e)

        If Not DesignMode Then

            _showTimer = New System.Windows.Forms.Timer

            _checkinout = True

            Opacity = 0

            'Timer1.Interval = 1000
            _showTimer.Enabled = True
        End If

    End Sub


    Private Sub timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles _showTimer.Tick

        If _checkinout = False Then
            Opacity -= (_showTimer.Interval / 1000.0)
            If Me.Opacity > 0 Then
                _showTimer.Enabled = True
            Else
                _showTimer.Enabled = False
                Close()
            End If
        Else
            Try
                Opacity += (_showTimer.Interval / 1000.0)
                _showTimer.Enabled = (Opacity < 1.0)
                _checkinout = (Opacity < 1.0)
            Catch odex As ObjectDisposedException

            End Try
        End If

    End Sub

    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Close()
    End Sub

    Private Sub btnOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpen.Click
        Me.Visible = False
        _benachrichtigung.Action()
        Close()
    End Sub

    Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
        LibMultiPlug.Core.Benachrichtigungen.BenachrichtigungsManager.GetInstance().DeleteBenachrichtigung(_benachrichtigung)
        Close()
    End Sub
End Class